package com.qumap.item.test.iteminfo.item2.info;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.NumberLabel;
import com.google.gwt.user.client.ui.Widget;
import com.qumap.item.content.ObjectOnMap;
import com.qumap.item.ItemOnMap;
import com.qumap.item.IITemInfoDisplay;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 26.06.11
 * Time: 19:52
 * To change this template use File | Settings | File Templates.
 */
public class T2InfoDisplay implements IITemInfoDisplay  {

    @UiTemplate("T2InfoDisplay.ui.xml")
    interface T2InfoDisplayUiBinder extends UiBinder<HTMLPanel, T2InfoDisplay> {
    }

    private static T2InfoDisplayUiBinder ourUiBinder = GWT.create(T2InfoDisplayUiBinder.class);
    private Widget root;
    @UiField
    Label item_type_label;
    @UiField
    Label item_id_label;
    @UiField
    NumberLabel longtitude_label;
    @UiField
    NumberLabel lattitude_label;
    @UiField
    NumberLabel db_id;
    @UiField
    Label description_field;

    public T2InfoDisplay() {
        root = ourUiBinder.createAndBindUi(this);

    }

    @Override
    public void getStateFromItem(ItemOnMap item) {

        clear();

        item_id_label.setText(Integer.toString(item.getId()));
        item_type_label.setText(item.getItemInfo().getType());
        longtitude_label.setValue(item.getLongtitude());
        lattitude_label.setValue(item.getLattitude());
        db_id.setValue(item.getContent().getId());
        description_field.setText(((ObjectOnMap)item.getContent()).getDescription());
    }

    @Override
    public void putStateToItem(ItemOnMap item) {
    }

    public void clear() {
        item_id_label.setText("");
        item_type_label.setText("");
        longtitude_label.setValue(0.0);
        lattitude_label.setValue(0.0);
        db_id.setValue(0);
        description_field.setText("");
    }

    @Override
    public Widget asWidget() {
        return root;  //To change body of implemented methods use File | Settings | File Templates.
    }

}